<template>
  <div>
    <div style="margin-left: 2%">
      <h1>借阅记录统计</h1>
      <div style="float: left" id="dv01" class="dvecharts"></div>
      <div style="float: right" id="dv02" class="dvecharts"></div>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'DeptEcharts',
  data(){
    return{
      recstuEcharts:{},
      recstuOption:{},
      recbookEcharts:{},
      recbookOption:{}
    }
  },
  mounted() {
    this.initEcharts1();
    this.initEcharts2();
  },
  methods:{
    initEcharts1(){
      // 基于准备好的dom，初始化echarts实例
      this.recstuEcharts = this.$echarts.init(document.getElementById('dv01'));


      // 指定图表的配置项和数据
      this.recstuOption = {
        title: {
          text: '人员借阅数量统计'
        },
        tooltip: {},
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: { readOnly: false },
            magicType: { type: ['line', 'bar'] },
            restore: {},
            saveAsImage: {}
          }
        },
        legend: {
          data: ['借书量']
        },
        xAxis: {
          data: ['研发部', '财务部', '人力部', '市场部', '行政部', '总经办']
        },
        yAxis: {},
        series: [
          {
            name: '借书量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      };
      //请求接口 获取真实数据
      request({
        url:"library/record/echartsStu.do"
      }).then(res=>{
        this.recstuOption.xAxis.data=res.data.name;
        this.recstuOption.series[0].data=res.data.num;
        // 使用刚指定的配置项和数据显示图表。
        this.recstuEcharts.setOption(this.recstuOption);
      })

    }
    ,
    initEcharts2(){
      // 基于准备好的dom，初始化echarts实例
      this.recbookEcharts = this.$echarts.init(document.getElementById('dv02'));

      // 指定图表的配置项和数据
      this.recbookOption = {
        title: {
          text: '图书借阅数量统计'
        },
        tooltip: {},
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: { readOnly: false },
            magicType: { type: ['line', 'bar'] },
            restore: {},
            saveAsImage: {}
          }
        },
        legend: {
          data: ['借阅量']
        },
        xAxis: {
          data: ['研发部', '财务部', '人力部', '市场部', '行政部', '总经办']
        },
        yAxis: {},
        series: [
          {
            name: '借阅量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      };
      //请求接口 获取真实数据
      request({
        url:"library/record/echartsBook.do"
      }).then(res=>{
        this.recbookOption.xAxis.data=res.data.name;
        this.recbookOption.series[0].data=res.data.num;
        // 使用刚指定的配置项和数据显示图表。
        this.recbookEcharts.setOption(this.recbookOption);
      })

    }
  }
}
</script>

<style scoped>
.dvecharts{
  width: 50%;
  height: 400px;
}
</style>
